{{ $logo       := site.Params.logos.panel }}
{{ $currentUrl := .RelPermalink }}
{{ $editUrl    := printf "https://github.com/etcd-io/website/edit/master/content/%s" .File.Path }}
{{ $latest     := site.Params.versions.latest }}
{{ $ghUrl      := printf "https://github.com/etcd-io/etcd/releases/tag/v%s" $latest }}
{{ $versions   := site.Params.versions.all }}
{{ $version    := index (split .Path "/") 1 }}
{{ $allDocs    := where site.Sections "Section" "docs" }}
{{ $currentUrl := .RelPermalink }}
<div class="dashboard-panel is-medium has-background-white-bis is-hidden-mobile">
  <div class="dashboard-panel-header has-text-centered">
    <a href="{{ .Site.BaseURL }}">
      <img class="is-panel-logo" src="{{ $logo }}">
    </a>

    <br /><br />

    <div class="dropdown">
      <div class="dropdown-trigger">
        <button class="button is-danger is-radiusless">
          <span>
            <strong>
              {{ $version }}
            </strong>
          </span>
          <span class="icon is-small">
            <i class="fas fa-angle-down" aria-hidden="true"></i>
          </span>
        </button>
      </div>

      <div class="dropdown-menu">
        <div class="dropdown-content">
          {{ range $versions }}
          {{ $v           := printf "v%s" . }}
          {{ $latest      := printf "v%s" $latest }}
          {{ $isLatest    := eq $v $latest }}
          <a class="navbar-item" href="/docs/v{{ . }}">
            {{ . }}
            {{ if $isLatest }}
            (<strong>latest</strong>)
            {{ end }}
          </a>
          {{ end }}
        </div>
      </div>
    </div>
  </div>

  <div class="dashboard-panel-main is-scrollable">
    <div class="docs-panel">
      <a class="docs-panel-section" href="/docs/{{ $version }}">
        Version {{ $version | replaceRE "v" "" }} home
      </a>

      {{ range $allDocs }}
      {{ range .Sections }}
      {{ range .RegularPages }}
      {{ if .Title }}
      {{ $docVersion := index (split .File.Path "/") 1 }}
      {{ if eq $docVersion $version }}
      {{ $isCurrentPage := eq .RelPermalink $currentUrl }}
      <a class="docs-panel-page{{ if $isCurrentPage }} is-active{{ end }}" href="{{ .RelPermalink }}">
        {{ .Title }}
      </a>
      {{ end }}
      {{ end }}
      {{ end }}


      {{ range .Sections }}
      {{ $docVersion := index (split .File.Path "/") 1 }}
      {{ if eq $docVersion $version }}
      {{ $isCurrentSection := eq .RelPermalink $currentUrl }}
      <a class="docs-panel-section{{ if $isCurrentSection }} is-active{{ end }}" href="{{ .RelPermalink }}">
        {{ .Title }}
      </a>

      {{ range .Pages }}
      {{ if .Title }}
      {{ $isCurrentPage := eq .RelPermalink $currentUrl }}
      <a class="docs-panel-page{{ if $isCurrentPage }} is-active{{ end }}" href="{{ .RelPermalink }}">
        {{ .Title }}
      </a>
      {{ end }}
      {{ end }}
      {{ end }}
      {{ end }}
      {{ end }}
      {{ end }}
    </div>
  </div>

  <div class="dashboard-panel-footer">
    <div class="buttons is-centered">
      <a class="button is-black" href="{{ $editUrl }}" target="_blank">
        <span class="icon">
          <i class="fab fa-github"></i>
        </span>
        <span class="has-text-weight-bold">
          Edit this page
        </span>
      </a>
    </div>
  </div>
</div>
